//
//  SetViewController.m
//  Vpay
//
//  Created by 伟大大 on 2018/9/20.
//  Copyright © 2018年 丁伟佳. All rights reserved.
//

#import "SetViewController.h"
#import "SetTableViewCell.h"
#import "NicknameViewController.h"
#import "ChangelogpassViewController.h"
#import "ChangeZFViewController.h"
#import "TSJYViewController.h"
#import "NewWebViewController.h"
#import "LoginViewController.h"
@interface SetViewController ()

@end

@implementation SetViewController

#pragma mark -
#pragma mark - for lifeCircle
#pragma mark -
- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:NO];

}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    //    [self.navigationController setNavigationBarHidden:YES animated:NO];
    
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
//        [self.navigationController setNavigationBarHidden:NO animated:NO];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"设置";
    self.view = [[[NSBundle mainBundle]loadNibNamed:@"SetViewController" owner:self options:nil]lastObject];
    self.view.backgroundColor = BACKCOLOR;
    
    
    
    [self initData];
    [self initNavBtns];
    [NSThread detachNewThreadSelector:@selector(requestPersonData) toTarget:self withObject:nil];

    [self initViews];
    

}
#pragma mark -
#pragma mark - for data
#pragma mark -
- (void)initData {
    
    self.array1 = [NSArray array];
    self.array2 = [NSArray array];
    self.array3 = [NSArray array];
    self.array4 = [NSArray array];
    self.array5 = [NSArray array];
    self.array6 = [NSArray array];

}
#pragma mark -
#pragma mark - for Views
#pragma mark -

- (void)initNavBtns {
    
    self.navigationItem.leftBarButtonItem = [AppUtility getNavBtnItemLefBacktWith:@selector(leftNavBtnClicked) andTarget:self];
}
- (void)initViews {
    
    self.userimage.layer.masksToBounds = YES;
    self.userimage.layer.cornerRadius = self.userimage.frame.size.width/2;
    
    self.array1 = @[NSLocalizedString(@"setnicheng", nil),NSLocalizedString(@"setlanguage", nil)];
    self.array2 = @[NSLocalizedString(@"setmycard", nil),NSLocalizedString(@"setzc", nil)];
    self.array3 = @[NSLocalizedString(@"setdlmm", nil),NSLocalizedString(@"setzfmm", nil),NSLocalizedString(@"setaqkl", nil)];
    self.array4 = @[NSLocalizedString(@"setgg", nil),NSLocalizedString(@"setgrxx", nil)];
    self.array5 = @[NSLocalizedString(@"setmydp", nil),NSLocalizedString(@"setmydd", nil),NSLocalizedString(@"setdzgl", nil)];
    self.array6 = @[NSLocalizedString(@"settsjy", nil),NSLocalizedString(@"setshare", nil),NSLocalizedString(@"setversion", nil),NSLocalizedString(@"setabout", nil)];
    
    
    self.imagearray1 = @[@"set_nicheng",@"set_duoyuyan"];
    self.imagearray2 = @[@"set_yinghangka",@"zichan"];
    self.imagearray3 = @[@"set_denglumima",@"set_zhifumima",@"set_safe"];
    self.imagearray4 = @[@"set_gonggao",@"set_gerenxiaoxi"];
    self.imagearray5 = @[@"set_dianpu",@"set_dingdan",@"set_dizhiguanli"];
    self.imagearray6 = @[@"set_toushujianyi",@"set_fenxiang",@"set_banben",@"set_guanyu"];
    
    self.xy_label.text = NSLocalizedString(@"xy", nil);
    self.Changeavar_label.text = NSLocalizedString(@"setchangavar", nil);
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(TapAction)];
    [self.TopView addGestureRecognizer:tap];
    
    self.MyTableView.scrollEnabled = YES;
    self.MyTableView.showsVerticalScrollIndicator = NO;
    self.MyTableView.showsHorizontalScrollIndicator = NO;
    self.MyTableView.delegate = self;
    self.MyTableView.dataSource = self;
    self.MyTableView.rowHeight = 41*theApp.autoSizeScaleY;
    self.MyTableView.backgroundColor = BACKCOLOR;
    self.MyTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    self.MyTableView.tableHeaderView = self.TopView;
    
//    self.MyTableView.frame = CGRectMake(0, self.MyTableView.frame.origin.y, self.MyTableView.frame.size.width, self.MyTableView.rowHeight*6+42*theApp.autoSizeScaleY);
    
    self.myScrollView.contentSize = CGSizeMake(0, self.MyTableView.frame.origin.y+self.MyTableView.frame.size.height+100*theApp.autoSizeScaleY);
}

-(void)requestPersonData
{
    
    NSDictionary *resultDict_hot =[NetUtility getDataWithURLStr:[NSString stringWithFormat:@"%@userid=%@&isApp=1",KURLUserInfo,@""] andPostStr:nil];
    
    UEXNSLog(@"URL = %@ ,resultDict_hot=%@",KURLUserInfo,resultDict_hot);
    
    if ([[resultDict_hot objectForKey:@"s"] intValue]==1) {
        
        [userDic removeAllObjects];
        
        //        [myArray addObjectsFromArray:[resultDict_hot objectForKey:@"d"]];
        userDic = [[NSMutableDictionary alloc]initWithDictionary:[resultDict_hot objectForKey:@"d"]];
        
        
    }else if ([[resultDict_hot objectForKey:@"s"] intValue]==303) {
        
        LoginViewController *vc = [[LoginViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
        return;
    }
    
    [self performSelectorOnMainThread:@selector(RefreshView) withObject:nil waitUntilDone:NO];
    
}
- (void)RefreshView {
    SLog(@"uid=%@",userDic[@"uinfo"][@"userid"]);
    SLog(@"iamge=%@",userDic[@"uinfo"][@"img_head"]);
    
    self.UID_label.text = [NSString stringWithFormat:@"UID：%@",userDic[@"uinfo"][@"userid"]];

    [self.userimage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",userDic[@"uinfo"][@"img_head"]]] placeholderImage:[AppUtility getLocalImage:@"image_Listmr"]];
    
    if ([userDic[@"uinfo"][@"user_credit"] isEqualToString:@"1"]) {
        self.XYimageView1.hidden = NO;
        self.XYimageView2.hidden = YES;
        self.XYimageView3.hidden = YES;
        self.XYimageView4.hidden = YES;
        self.XYimageView5.hidden = YES;
    }else if ([userDic[@"uinfo"][@"user_credit"] isEqualToString:@"2"]) {
        self.XYimageView1.hidden = NO;
        self.XYimageView2.hidden = NO;
        self.XYimageView3.hidden = YES;
        self.XYimageView4.hidden = YES;
        self.XYimageView5.hidden = YES;
    }else if ([userDic[@"uinfo"][@"user_credit"] isEqualToString:@"3"]) {
        self.XYimageView1.hidden = NO;
        self.XYimageView2.hidden = NO;
        self.XYimageView3.hidden = NO;
        self.XYimageView4.hidden = YES;
        self.XYimageView5.hidden = YES;
    }else if ([userDic[@"uinfo"][@"user_credit"] isEqualToString:@"4"]) {
        self.XYimageView1.hidden = NO;
        self.XYimageView2.hidden = NO;
        self.XYimageView3.hidden = NO;
        self.XYimageView4.hidden = NO;
        self.XYimageView5.hidden = YES;
    }else if ([userDic[@"uinfo"][@"user_credit"] isEqualToString:@"5"]) {
        self.XYimageView1.hidden = NO;
        self.XYimageView2.hidden = NO;
        self.XYimageView3.hidden = NO;
        self.XYimageView4.hidden = NO;
        self.XYimageView5.hidden = NO;
    }
    
    [self.MyTableView reloadData];
}
#pragma mark -
#pragma mark for delegates
#pragma mark -
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 7;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    switch(section) {
            
        case 0: return 1;  break;
            
        case 1: return self.array2.count; break;
            
        case 2: return 2; break;
            
        case 3: return self.array4.count; break;
            
        case 4: return self.array5.count; break;
            
        case 5: return self.array6.count; break;
        
        case 6: return 1; break;
            
        default: return 0; break;
            
    }
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//    NSMutableDictionary *dic = [self.array objectAtIndex:indexPath.row] ;
    UITableViewCell *cell = nil;
    SetTableViewCell *cell1 = [self.MyTableView dequeueReusableCellWithIdentifier:@"SetTableViewCell"];
    if (!cell1)
    {
        cell1 = [[SetTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SetTableViewCell"];
        
    }
    switch(indexPath.section) {
            
        case 0: cell1.settitle_label.text = self.array1[indexPath.row];
            if (indexPath.row == 0) {
                cell1.text_label.text = userDic[@"uinfo"][@"username"];
                cell1.setimageView.image = [AppUtility getLocalImage:@"set_niceng"];
            }else {
                cell1.text_label.text = NSLocalizedString(@"language", nil);
                cell1.setimageView.image = [AppUtility getLocalImage:@"set_duoyuyan"];

            }
            break;
            
        case 1: cell1.settitle_label.text = self.array2[indexPath.row];cell1.text_label.hidden = YES;
            
            cell1.setimageView.image = [AppUtility getLocalImage:self.imagearray2[indexPath.row]];
            break;
            
        case 2: cell1.settitle_label.text = self.array3[indexPath.row];
            if (indexPath.row == 2) {
                cell1.text_label.text = NSLocalizedString(@"setczankl", nil);
            }else {
                cell1.text_label.text = NSLocalizedString(@"setxgdlmm", nil);
            }
            cell1.setimageView.image = [AppUtility getLocalImage:self.imagearray3[indexPath.row]];

            break;
            
        case 3: cell1.settitle_label.text = self.array4[indexPath.row];cell1.text_label.hidden = YES;
            cell1.setimageView.image = [AppUtility getLocalImage:self.imagearray4[indexPath.row]];
            break;
            
        case 4: cell1.settitle_label.text = self.array5[indexPath.row];cell1.text_label.hidden = YES;
            cell1.setimageView.image = [AppUtility getLocalImage:self.imagearray5[indexPath.row]];

            break;
            
        case 5: cell1.settitle_label.text = self.array6[indexPath.row];
            cell1.setimageView.image = [AppUtility getLocalImage:self.imagearray6[indexPath.row]];

            if (indexPath.row == 2) {
                cell1.text_label.text = userDic[@"app_version"];
            }else {
                cell1.text_label.hidden = YES;
            }
            break;
            
        case 6:cell1.setimageView.hidden = YES;
            cell1.settitle_label.frame = CGRectMake(0, 0, cell1.frame.size.width, 40);
            cell1.settitle_label.textColor = BLUECOLOR;
            cell1.settitle_label.font = [UIFont systemFontOfSize:15];
            cell1.settitle_label.text = NSLocalizedString(@"setlogout", nil);
            cell1.text_label.hidden = YES;
            cell1.settitle_label.textAlignment = NSTextAlignmentCenter;
            cell1.JT_image.hidden = YES;
            break;
            
        default: return 0; break;
            
    }
    cell1.selectionStyle = NO;
    
    
    
    cell = cell1;
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    switch(indexPath.section) {
            
        case 0:
            if (indexPath.row == 0) {
                NicknameViewController *vc = [[NicknameViewController alloc]init];
                vc.nickname = userDic[@"uinfo"][@"username"];
                [self.navigationController pushViewController:vc animated:YES];
                
            }else {
                
            }
            break;
            
        case 1:
            if (indexPath.row == 0) {
                NSDictionary *resultDict_hot =[NetUtility getDataWithURLStr:[NSString stringWithFormat:@"%@userid=%@&isApp=1",KURLUserInfo,@""] andPostStr:nil];
                
                UEXNSLog(@"URL = %@ ,resultDict_hot=%@",KURLUserInfo,resultDict_hot);
                
                if ([resultDict_hot[@"s"] intValue] == 303) {
                    [self.navigationController.view makeToast:resultDict_hot[@"i"]];
                    
                    [[NSUserDefaults standardUserDefaults]removeObjectForKey:KUDAppTDWNO];
                    [[NSUserDefaults standardUserDefaults]removeObjectForKey:KUDAppTDWPass];
                    
                    LoginViewController *vc = [[LoginViewController alloc]init];
                    [self.navigationController pushViewController:vc animated:YES];
                    
                    return;
                    
                }
                LXWebViewController *vc = [[LXWebViewController alloc]init];
                vc.LXtitle = @"我的银行卡";
                vc.urlStr = @"http://vpay1.luck8868.com/Growth/Cardinfos.html";
                [self.navigationController pushViewController:vc animated:YES];
            }else if (indexPath.row == 1){
                NSDictionary *resultDict_hot =[NetUtility getDataWithURLStr:[NSString stringWithFormat:@"%@userid=%@&isApp=1",KURLUserInfo,@""] andPostStr:nil];
                
                UEXNSLog(@"URL = %@ ,resultDict_hot=%@",KURLUserInfo,resultDict_hot);
                
                if ([resultDict_hot[@"s"] intValue] == 303) {
                    [self.navigationController.view makeToast:resultDict_hot[@"i"]];
                    
                    [[NSUserDefaults standardUserDefaults]removeObjectForKey:KUDAppTDWNO];
                    [[NSUserDefaults standardUserDefaults]removeObjectForKey:KUDAppTDWPass];
                    
                    LoginViewController *vc = [[LoginViewController alloc]init];
                    [self.navigationController pushViewController:vc animated:YES];
                    
                    return;
                    
                }
                LXWebViewController *vc = [[LXWebViewController alloc]init];
                vc.LXtitle = @"我的资产";
                vc.urlStr = @"http://vpay1.luck8868.com/Tibi/zichan.html";
                [self.navigationController pushViewController:vc animated:YES];
                
            }
            break;
            
        case 2:
            if (indexPath.row == 0) {
                
                ChangelogpassViewController *vc = [[ChangelogpassViewController alloc]init];
//                vc.xgType = @"";
                [self.navigationController pushViewController:vc animated:YES];
                
            }else if (indexPath.row == 1){
                
                ChangeZFViewController *vc = [[ChangeZFViewController alloc]init];
//                vc.xgType = @"xgzf";
                [self.navigationController pushViewController:vc animated:YES];
                
            }else if (indexPath.row == 2) {
                
                UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"每天只能充值1次安全口令，是否确认重置?" message:nil preferredStyle:UIAlertControllerStyleAlert];
//                __weak __typeof(self) weakSelf = self;
                UIAlertAction *action = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    //取消
                }];
                UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    //确定
                    
                }];
                [alertVC addAction:action];
                [alertVC addAction:action1];
                
                [self presentViewController:alertVC animated:YES completion:^{
                }];
            }
            
            
            break;
            
        case 3:
            
            if (indexPath.row == 0) {
                NSDictionary *resultDict_hot =[NetUtility getDataWithURLStr:[NSString stringWithFormat:@"%@userid=%@&isApp=1",KURLUserInfo,@""] andPostStr:nil];
                
                UEXNSLog(@"URL = %@ ,resultDict_hot=%@",KURLUserInfo,resultDict_hot);
                
                if ([resultDict_hot[@"s"] intValue] == 303) {
                    [self.navigationController.view makeToast:resultDict_hot[@"i"]];
                    
                    [[NSUserDefaults standardUserDefaults]removeObjectForKey:KUDAppTDWNO];
                    [[NSUserDefaults standardUserDefaults]removeObjectForKey:KUDAppTDWPass];
                    
                    LoginViewController *vc = [[LoginViewController alloc]init];
                    [self.navigationController pushViewController:vc animated:YES];
                    
                    return;
                    
                }
                LXWebViewController *vc = [[LXWebViewController alloc]init];
                vc.LXtitle = @"公告";
                vc.urlStr = @"http://vpay1.luck8868.com/User/News.html";
                [self.navigationController pushViewController:vc animated:YES];
                
            }else if (indexPath.row == 1){
                NSDictionary *resultDict_hot =[NetUtility getDataWithURLStr:[NSString stringWithFormat:@"%@userid=%@&isApp=1",KURLUserInfo,@""] andPostStr:nil];
                
                UEXNSLog(@"URL = %@ ,resultDict_hot=%@",KURLUserInfo,resultDict_hot);
                
                if ([resultDict_hot[@"s"] intValue] == 303) {
                    [self.navigationController.view makeToast:resultDict_hot[@"i"]];
                    
                    [[NSUserDefaults standardUserDefaults]removeObjectForKey:KUDAppTDWNO];
                    [[NSUserDefaults standardUserDefaults]removeObjectForKey:KUDAppTDWPass];
                    
                    LoginViewController *vc = [[LoginViewController alloc]init];
                    [self.navigationController pushViewController:vc animated:YES];
                    
                    return;
                    
                }
                LXWebViewController *vc = [[LXWebViewController alloc]init];
                vc.LXtitle = @"个人消息";
                vc.urlStr = @"http://vpay1.luck8868.com/Tpl/wap/tibi/msg.html";
                [self.navigationController pushViewController:vc animated:YES];
            }
            break;
            
        case 4:
            if (indexPath.row == 0) {
                NSDictionary *resultDict_hot =[NetUtility getDataWithURLStr:[NSString stringWithFormat:@"%@userid=%@&isApp=1",KURLUserInfo,@""] andPostStr:nil];
                
                UEXNSLog(@"URL = %@ ,resultDict_hot=%@",KURLUserInfo,resultDict_hot);
                
                if ([resultDict_hot[@"s"] intValue] == 303) {
                    [self.navigationController.view makeToast:resultDict_hot[@"i"]];
                    
                    [[NSUserDefaults standardUserDefaults]removeObjectForKey:KUDAppTDWNO];
                    [[NSUserDefaults standardUserDefaults]removeObjectForKey:KUDAppTDWPass];
                    
                    LoginViewController *vc = [[LoginViewController alloc]init];
                    [self.navigationController pushViewController:vc animated:YES];
                    
                    return;
                    
                }
                LXWebViewController *vc = [[LXWebViewController alloc]init];
                vc.LXtitle = @"我的店铺";
                vc.urlStr = @"http://vpay1.luck8868.com/Shop/Member/mine.html";
                [self.navigationController pushViewController:vc animated:YES];
            }else if (indexPath.row == 1){
                NSDictionary *resultDict_hot =[NetUtility getDataWithURLStr:[NSString stringWithFormat:@"%@userid=%@&isApp=1",KURLUserInfo,@""] andPostStr:nil];
                
                UEXNSLog(@"URL = %@ ,resultDict_hot=%@",KURLUserInfo,resultDict_hot);
                
                if ([resultDict_hot[@"s"] intValue] == 303) {
                    [self.navigationController.view makeToast:resultDict_hot[@"i"]];
                    
                    [[NSUserDefaults standardUserDefaults]removeObjectForKey:KUDAppTDWNO];
                    [[NSUserDefaults standardUserDefaults]removeObjectForKey:KUDAppTDWPass];
                    
                    LoginViewController *vc = [[LoginViewController alloc]init];
                    [self.navigationController pushViewController:vc animated:YES];
                    
                    return;
                    
                }
                LXWebViewController *vc = [[LXWebViewController alloc]init];
                vc.LXtitle = @"我的订单";
                vc.urlStr = @"http://vpay1.luck8868.com/Shop/Member/allorder.html";
                [self.navigationController pushViewController:vc animated:YES];
                
            }else if (indexPath.row == 2){
                NSDictionary *resultDict_hot =[NetUtility getDataWithURLStr:[NSString stringWithFormat:@"%@userid=%@&isApp=1",KURLUserInfo,@""] andPostStr:nil];
                
                UEXNSLog(@"URL = %@ ,resultDict_hot=%@",KURLUserInfo,resultDict_hot);
                
                if ([resultDict_hot[@"s"] intValue] == 303) {
                    [self.navigationController.view makeToast:resultDict_hot[@"i"]];
                    
                    [[NSUserDefaults standardUserDefaults]removeObjectForKey:KUDAppTDWNO];
                    [[NSUserDefaults standardUserDefaults]removeObjectForKey:KUDAppTDWPass];
                    
                    LoginViewController *vc = [[LoginViewController alloc]init];
                    [self.navigationController pushViewController:vc animated:YES];
                    
                    return;
                    
                }
                LXWebViewController *vc = [[LXWebViewController alloc]init];
                vc.LXtitle = @"地址管理";
                vc.urlStr = @"http://vpay1.luck8868.com/Shop/member/addresslist.html";
                [self.navigationController pushViewController:vc animated:YES];
                
            }
            break;
            
        case 5:
            if (indexPath.row == 0) {
                TSJYViewController *vc = [[TSJYViewController alloc]init];
                //                vc.xgType = @"";
                [self.navigationController pushViewController:vc animated:YES];
            }else if (indexPath.row == 1){
                NSDictionary *resultDict_hot =[NetUtility getDataWithURLStr:[NSString stringWithFormat:@"%@userid=%@&isApp=1",KURLUserInfo,@""] andPostStr:nil];
                
                UEXNSLog(@"URL = %@ ,resultDict_hot=%@",KURLUserInfo,resultDict_hot);
                
                if ([resultDict_hot[@"s"] intValue] == 303) {
                    [self.navigationController.view makeToast:resultDict_hot[@"i"]];
                    
                    [[NSUserDefaults standardUserDefaults]removeObjectForKey:KUDAppTDWNO];
                    [[NSUserDefaults standardUserDefaults]removeObjectForKey:KUDAppTDWPass];
                    
                    LoginViewController *vc = [[LoginViewController alloc]init];
                    [self.navigationController pushViewController:vc animated:YES];
                    
                    return;
                    
                }
                LXWebViewController *vc = [[LXWebViewController alloc]init];
                vc.LXtitle = @"分享";
                vc.mytype = @"fx";
                vc.urlStr = @"http://vpay1.luck8868.com/User/Sharecode.html";
                [self.navigationController pushViewController:vc animated:YES];
            }else if (indexPath.row == 2){
                
            }else if (indexPath.row == 3) {
                NSDictionary *resultDict_hot =[NetUtility getDataWithURLStr:[NSString stringWithFormat:@"%@userid=%@&isApp=1",KURLUserInfo,@""] andPostStr:nil];
                
                UEXNSLog(@"URL = %@ ,resultDict_hot=%@",KURLUserInfo,resultDict_hot);
                
                if ([resultDict_hot[@"s"] intValue] == 303) {
                    [self.navigationController.view makeToast:resultDict_hot[@"i"]];
                    
                    [[NSUserDefaults standardUserDefaults]removeObjectForKey:KUDAppTDWNO];
                    [[NSUserDefaults standardUserDefaults]removeObjectForKey:KUDAppTDWPass];
                    
                    LoginViewController *vc = [[LoginViewController alloc]init];
                    [self.navigationController pushViewController:vc animated:YES];
                    
                    return;
                    
                }
                LXWebViewController *vc = [[LXWebViewController alloc]init];
                vc.LXtitle = @"关于";
                vc.urlStr = @"http://vpay1.luck8868.com/User/Aboutus.html";
                [self.navigationController pushViewController:vc animated:YES];
            }
           
            break;
            
            case 6:
            [self LogOut];
            break;
        default:
            break;
            
    }
    
}
- (void)LogOut {
    
    NSString *postStr = @"";
    NSDictionary *resultDict =[NetUtility getDataWithURLStr:[NSString stringWithFormat:@"%@",KURLLogout] andPostStr:nil andView:self.navigationController.view];
    
    UEXNSLog(@"kURL==%@%@ resultDict=%@",KURLLogout,postStr,resultDict);
    if (resultDict) {
        int stauts = [[resultDict objectForKey:@"s"] intValue];
        if (stauts==1) {
            
            
            [AccountController logout];
            [[NSUserDefaults standardUserDefaults]removeObjectForKey:KUDAppTDWNO];
            [[NSUserDefaults standardUserDefaults]removeObjectForKey:KUDAppTDWPass];
            
            //                    [theApp islogout];
            
            LoginViewController *vc = [[LoginViewController alloc]init];
            //                    vc.logType = @"logout";
            [self.navigationController pushViewController:vc animated:YES];
            
            
            
            
        }else if (stauts == 404) {
            LoginViewController *vc = [[LoginViewController alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
            return;
        }
//        [self.navigationController.view makeToast:[resultDict objectForKey:@"i"] duration:1.0 position:@"center" title:nil image:[AppUtility getLocalImage:@"error"]];
        
        [self.navigationController.view makeToast:[resultDict objectForKey:@"i"]];
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    if (section == 5) {
        return 10;
    }else if (section == 6) {
        return 1;

    }else {
        return 5;
    }
}
- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section {
    view.tintColor = BACKCOLOR;
}
#pragma mark -
#pragma mark for evevts
#pragma mark -
- (void)leftNavBtnClicked {
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)TapAction {
    [self chooseImage];
}

-(void)chooseImage {
    self.imagePicker = [[UIImagePickerController alloc] init];
    self.imagePicker.delegate = self;
    self.imagePicker.allowsEditing = YES;
    
    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction *cameraAction = [UIAlertAction actionWithTitle:@"手机拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
            self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
            [self presentViewController:self.imagePicker animated:YES completion:nil];
        }
    }];
    
    UIAlertAction *photoAction = [UIAlertAction actionWithTitle:@"相册选择图片" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentViewController:self.imagePicker animated:YES completion:nil];
        
    }];
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"点击了取消");
    }];
    
    [actionSheet addAction:cameraAction];
    [actionSheet addAction:photoAction];
    [actionSheet addAction:cancelAction];
    
    [self presentViewController:actionSheet animated:YES completion:nil];
}
//获取选择的图片
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
    //    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    
    UIImage * image=[info objectForKey:UIImagePickerControllerEditedImage];
    
    
    [self performSelector:@selector(selectPic:) withObject:image afterDelay:0.1];
    
    
    
    [picker dismissViewControllerAnimated:YES completion:nil];
    
}
- (void)selectPic:(UIImage*)image
{
    
    NSMutableDictionary *resultDic = [NetUtility getDataWithURLStr:KURLheadpic andPostStr:nil andType:@"image/jpeg" andData:UIImageJPEGRepresentation(image,0.5) andDataKey:@"file"];


    UEXNSLog(@"avatar = %@",resultDic);
    
    if ([resultDic[@"s"] intValue] == 0) {
        [self.navigationController.view makeToast:resultDic[@"i"]];

    }
    else {
        [self.navigationController.view makeToast:@"头像修改成功"];
    }
    
    [NSThread detachNewThreadSelector:@selector(requestPersonData) toTarget:self withObject:nil];
//    [self.Person_imageView setImage:image];
    [self.MyTableView reloadData];
    
    
    return;
}
//从相机或者相册界面弹出
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [picker dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)dealloc {
    [_userimage release];
    [_UID_label release];
    [_XYimageView1 release];
    [_XYimageView2 release];
    [_XYimageView3 release];
    [_XYimageView4 release];
    [_XYimageView5 release];
    [_MyTableView release];
    [_myScrollView release];
    [_TopView release];
    [_Changeavar_label release];
    [_xy_label release];
    [super dealloc];
}
@end
